package application;
	
import java.io.FileInputStream;
import java.nio.charset.Charset;
import java.security.KeyStore;
import java.security.SecureRandom;

import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;

public class ClientConsts { 
	//TODO do we have to pull this in from props?
	public static final String USERACCOUNT_MD_ALG = "SHA-256";
		
	public static final String SSL_LOCAL_KEYSTORE_TYPE = "JKS";
	public static final String SSL_KEYMANAGER_ALGORITHM = "SunX509";
	public static final String SSL_VERSION = "SSLV3";
	// public static final String SERVER_IP = "10.159.117.103";
	public static final String SERVER_IP = "127.0.0.1";

	public static final int SERVER_PORT = 6811;
	public static final int SERVER_PORT_GAME = 6810;
	public static final int SERVER_PORT_USER_ACCOUNT = 6811;
	
	/* 
	 * SERVER_PORT_STATS is used for retrieving user rankings, current games
	 * other statistics for future.  validating a username/password pair, 
     */	
	public static final int SERVER_PORT_STATS = 6812;
	public static final int userNameMinLen = 11;
	public static final int authFailed = 1;
	public static final int authSuccess = 0;
	
	public static SSLSocketFactory createSSLFactory(){
		try{
			String jksPath = "resources/jeopardytrust.jks";
			char[] keyPassword = "yes a secure password!".toCharArray();
			FileInputStream keyFile = new FileInputStream(jksPath); 
	
			KeyStore keyStore = KeyStore.getInstance("JKS");
			keyStore.load(keyFile, keyPassword);
			KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
			keyManagerFactory.init(keyStore, keyPassword);
			KeyManager keyManagers[] = keyManagerFactory.getKeyManagers();
			
			TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
			tmf.init(keyStore);
			TrustManager tms[] = tmf.getTrustManagers();
			
			SSLContext sslContext = SSLContext.getInstance("SSLV3");
			//sslContext.init(keyManagers, null, new SecureRandom());
			sslContext.init(null, tms, new SecureRandom());
			SSLSocketFactory socketFactory = sslContext.getSocketFactory();
	
			keyFile.close();
			
			return socketFactory;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	

}
